﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool.BLL
{
    public class B_Menu
    {
        private PetaPoco.Database db;
        public B_Menu()
        {
            db = new PetaPoco.Database("ConnectionString");
        }

        public DataTable GetAll()
        {
            DataTable dt = new DataTable();
            dt = db.ExecuteReader("EXEC Menu_Get_List");
            return dt;
        }

        //public DataTable GetBy_MenuParentID(int ParentID)
        //{
        //    DataTable dt = new DataTable();
        //    dt = db.ExecuteReader("EXEC Menu_GetByParentId @ParentId = " + ParentID + "");
        //    //dt = db.get_data("EXEC Menu_GetByParentId @ParentId = " + ParentID + "");
        //    return dt;

        //}
        public List<M_Menu> GetAlls()
        {
            var menu = db.Fetch<M_Menu>(@";EXEC Menu_Get_List");
            return menu;
        }

        public M_Menu GetByPK(int MenuID)
        {
            var loadmenu = db.SingleOrDefault<M_Menu>("SELECT * FROM Menu m WHERE m.MenuID = " + MenuID + ";");
            db.CloseSharedConnection();
            return loadmenu;
        }

        public List<M_Menu> GetBy_MenuParentID(int ParentID, int MenuTypeID)
        {
            var menu = db.Fetch<M_Menu>(@";EXEC Menu_GetByParentId @@ParentId = @0, @@MenuTypeId = @1", ParentID, MenuTypeID);
            return menu;
        }

        public List<M_Menu> GetBy_MenuTypeID(int MenuTypeID)
        {
            var menu = db.Fetch<M_Menu>(@";EXEC Menu_GetByMenuTypeId @@MenuTypeId = @0", MenuTypeID);
            return menu;
        }
    }
}